﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CRUD;

namespace Client
{
    public partial class PersonListF : Form,IView
    {
        public IPresenter ip = null;
        MyList list = null;
        public PersonF secF = new PersonF();
        public PersonListF()
        {
            InitializeComponent();
        }
        public void show(MyList p) 
        {
            list = p;
            PersonListV.Rows.Clear();
            foreach (Person pp in p)
            {
                PersonListV.Rows.Add(pp.id, pp.FName, pp.LName, pp.Age);
            }        
        }
        private void On_Load(object sender, EventArgs e)
        {
            ip.read();
            secF.firstF = this;
            secF.ip = ip;
        }
        private void Delete_B_Click(object sender, EventArgs e)
        {           
            ip.delete(Convert.ToInt32(ID_box.Text));
        }
        private void Update_B_Click(object sender, EventArgs e)
        {
            Person a = null;
            foreach (Person pp in list)
            {
                if (pp.id == Convert.ToInt32(ID_box.Text))
                {
                    a = pp;
                }                
            }        
            secF.curper = a;
            secF.ShowThis();
            Hide();
        }
        private void Read_B_Click(object sender, EventArgs e)
        {
            ip.read();
        }
        private void Create_b_Click(object sender, EventArgs e)
        {
            Person a = null;           
            secF.curper = a;
            secF.ShowThis();
            Hide();
        }
    }
}
